﻿using Nasty.Core.Config;
using SqlSugar;

namespace Nasty.Core.Model
{

    public class DbConfigModel
    {
        public required string Type { get; set; }

        public DbType DbType
        {
            get
            {
                return GetDbType(this.Type);
            }
        }

        public required string ConnectionString { get; set; }

        public List<SlaveConnectionConfig> Slaves { get; set; } = new List<SlaveConnectionConfig>();

        public SnowFlake SnowFlake { get; set; } = new SnowFlake();

        public static DbType GetDbType(string type)
        {
            switch (type.ToLower())
            {
                case "mysql": return DbType.MySql;
                case "sqlserver": return DbType.SqlServer;
                case "sqlite": return DbType.Sqlite;
                case "oracle": return DbType.Oracle;
                case "postgresql": return DbType.PostgreSQL;
                case "dm": return DbType.Dm;
                case "kdbndp": return DbType.Kdbndp;
                case "oscar": return DbType.Oscar;
                case "mysqlconnector": return DbType.MySqlConnector;
                case "access": return DbType.Access;
                case "openGauss": return DbType.OpenGauss;
                case "questdb": return DbType.QuestDB;
                case "hg": return DbType.HG;
                case "clickhouse": return DbType.ClickHouse;
                case "gbase": return DbType.GBase;
                case "odbc": return DbType.Odbc;
                case "oceanbasefororacle": return DbType.OceanBaseForOracle;
                case "tdengine": return DbType.TDengine;
                case "gaussdb": return DbType.GaussDB;
                case "oceanbase": return DbType.OceanBase;
                case "tidb": return DbType.Tidb;
                case "vastbase": return DbType.Vastbase;
                case "polardb": return DbType.PolarDB;
                case "doris": return DbType.Doris;
                case "xugu": return DbType.Xugu;
                case "goldendb": return DbType.GoldenDB;
                case "custom": return DbType.Custom;
                default: return DbType.SqlServer;
            }

        }
    }


    public class SnowFlake
    {
        public string WorkId { get; set; }
        public string DatacenterId { get; set; }
    }
}
